package com.supreme.stockserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.supreme.stockserver.service.OrderService;
import com.supreme.common.entityVO.CreateOrderVO;
import com.supreme.commonmybatis.mapper.OrderMapper;
import com.supreme.commonentity.mysql.primary.BizOrder;
import com.supreme.commonboot.utils.AjaxResp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "order")
public class OrderController {

    @Resource
    private OrderMapper orderMapper;

    @Resource
    private OrderService orderService;

    @GetMapping(value = "search")
    public AjaxResp searchOrder() {
        QueryWrapper<BizOrder> queryWrapper = new QueryWrapper<>();
        List<BizOrder> orderList = this.orderMapper.selectList(queryWrapper);
        return new AjaxResp(orderList);
    }

    @PostMapping(value = "orders")
    public AjaxResp createOrder(@RequestBody CreateOrderVO createOrderVO) {
        orderService.createOrder(createOrderVO);
        return AjaxResp.instance();
    }
}
